<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="generator" content="VuePress 2.0.0-beta.32">
    <link rel="shortcut icon" href="/help/images/favicon.ico" type="image/x-icon"><title>如何新增一个模块 | PSI实施指南</title><meta name="description" content="PSI实施指南">
    <link rel="modulepreload" href="/help/assets/app.ae8b26c7.js"><link rel="modulepreload" href="/help/assets/100.html.ed854543.js"><link rel="modulepreload" href="/help/assets/plugin-vue_export-helper.21dcd24c.js"><link rel="modulepreload" href="/help/assets/100.html.f1573bea.js">
    <link rel="stylesheet" href="/help/assets/style.140447d0.css">
  </head>
  <body>
    <div id="app"><!--[--><div class="theme-container"><!--[--><header ref_key="navbar" class="navbar"><div class="toggle-sidebar-button" title="toggle sidebar" aria-expanded="false" role="button" tabindex="0"><div class="icon" aria-hidden="true"><span></span><span></span><span></span></div></div><span><a href="/help/" class=""><img class="logo" src="/help/images/logo.png" alt="PSI实施指南"><span class="site-name can-hide">PSI实施指南</span></a></span><div class="navbar-items-wrapper" style=""><!--[--><!--]--><nav class="navbar-items can-hide"><!--[--><div class="navbar-item"><a href="/help/user/" class="" aria-label="使用手册"><!--[--><!--]--> 使用手册 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/help/admin/" class="" aria-label="系统管理"><!--[--><!--]--> 系统管理 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/help/dev/" class="router-link-active" aria-label="二次开发"><!--[--><!--]--> 二次开发 <!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><button class="toggle-dark-button" title="toggle dark mode"><svg style="" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z" fill="currentColor"></path><path d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z" fill="currentColor"></path><path d="M2 15.005h5v2H2z" fill="currentColor"></path><path d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 25.005h2v5h-2z" fill="currentColor"></path><path d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z" fill="currentColor"></path><path d="M25 15.005h5v2h-5z" fill="currentColor"></path><path d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 2.005h2v5h-2z" fill="currentColor"></path></svg><svg style="display:none;" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z" fill="currentColor"></path></svg></button><!----></div></header><!--]--><div class="sidebar-mask"></div><!--[--><aside class="sidebar"><nav class="navbar-items"><!--[--><div class="navbar-item"><a href="/help/user/" class="" aria-label="使用手册"><!--[--><!--]--> 使用手册 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/help/admin/" class="" aria-label="系统管理"><!--[--><!--]--> 系统管理 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/help/dev/" class="router-link-active" aria-label="二次开发"><!--[--><!--]--> 二次开发 <!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><ul class="sidebar-items"><!--[--><li><a href="/help/dev/lcap/" class="sidebar-item sidebar-heading" aria-label="低代码应用平台"><!--[--><!--]--> 低代码应用平台 <!--[--><!--]--></a><!--[--><ul style="" class="sidebar-item-children"><!--[--><li><a href="/help/dev/lcap/08-05.html" class="sidebar-item" aria-label="解决方案"><!--[--><!--]--> 解决方案 <!--[--><!--]--></a><!----></li><li><a href="/help/dev/lcap/08-01.html" class="sidebar-item" aria-label="主菜单维护"><!--[--><!--]--> 主菜单维护 <!--[--><!--]--></a><!----></li><li><a href="/help/dev/lcap/08-03.html" class="sidebar-item" aria-label="码表设置"><!--[--><!--]--> 码表设置 <!--[--><!--]--></a><!----></li><li><a href="/help/dev/lcap/08-06.html" class="sidebar-item" aria-label="自定义表单"><!--[--><!--]--> 自定义表单 <!--[--><!--]--></a><!----></li><li><a href="/help/dev/lcap/08-04.html" class="sidebar-item" aria-label="视图开发助手"><!--[--><!--]--> 视图开发助手 <!--[--><!--]--></a><!----></li><li><a href="/help/dev/lcap/08-02.html" class="sidebar-item" aria-label="系统数据字典"><!--[--><!--]--> 系统数据字典 <!--[--><!--]--></a><!----></li><li><a href="/help/dev/lcap/08-07.html" class="sidebar-item" aria-label="FId一览"><!--[--><!--]--> FId一览 <!--[--><!--]--></a><!----></li><!--]--></ul><!--]--></li><li><p class="sidebar-item sidebar-heading active">二次开发 <!----></p><!--[--><ul style="" class="sidebar-item-children"><!--[--><li><a href="/help/dev/alone/" class="router-link-active sidebar-item active" aria-label="独立模块"><!--[--><!--]--> 独立模块 <!--[--><!--]--></a><!--[--><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/help/dev/alone/100.html" class="router-link-active router-link-exact-active router-link-active sidebar-item active" aria-label="如何新增一个模块"><!--[--><!--]--> 如何新增一个模块 <!--[--><!--]--></a><!----></li><!--]--></ul><!--]--></li><!--]--></ul><!--]--></li><!--]--></ul><!--[--><!--]--></aside><!--]--><!--[--><main class="page"><!--[--><!--]--><div class="theme-default-content"><!--[--><h1 id="如何新增一个模块" tabindex="-1"><a class="header-anchor" href="#如何新增一个模块" aria-hidden="true">#</a> 如何新增一个模块</h1><hr><p>1、fid</p><p><code>fid</code>是功能id的缩写。一个<code>fid</code>只要做到全局唯一即可，但是最好参考PSI现在的默认命名惯例。</p><p><code>fid</code>的定义在：<a href="https://gitee.com/crm8000/PSI/blob/master/web/Application/Home/Common/FIdConst.class.php" target="_blank" rel="noopener noreferrer">/web/Application/Home/Common/FIdConst.class.php<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a></p><p>2、主菜单</p><p>用户进入一个业务模块的操作入口是主菜单。</p><p>PSI的主菜单定义在数据库的表 <code>t_menu_item</code> 中，表结构的具体含义请参考 <a href="https://gitee.com/crm8000/PSI/tree/master/doc/02%20%E8%A1%A8%E7%BB%93%E6%9E%84" target="_blank" rel="noopener noreferrer">/doc/02 表结构/表结构说明.ods<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a>。</p><p><code>t_menu_item</code>中的一条记录就对应一个菜单项，所以新加一个模块，就需要向<code>t_menu_item</code>中添加一条新记录。</p><p>菜单的图标是用css实现的，该css文件在<a href="https://gitee.com/crm8000/PSI/blob/master/web/Public/Content/icons.css" target="_blank" rel="noopener noreferrer">PSI/web/Public/Content/icons.css<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a></p><p>例如：客户资料的fid是1007，那么它的图标在css中就是这么写的</p><div class="language-text ext-text line-numbers-mode"><pre class="language-text"><code>.PSI-fid1007 {
    background-image:url(../Images/fid/fid1007.png) !important;
}
</code></pre><div class="line-numbers"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>3、权限</p><p>给表 <code>t_permission</code> 中新增一条记录，对应于通过菜单进入业务模块的权限。</p><p>如果页面里面的按钮也需要权限控制，有几个权限项就再定义几个fid，并向表 <code>t_permission</code> 里面新增对应的记录。</p><p>4、编写业务模块Controller</p><p>Controller需要从PSIBaseController继承。</p><p>业务模块的入口页面通常的action就用index()。</p><p>下图是PermissionController的index()的方法。</p><p><img src="/help/assets/100-01.7c1289ff.jpg" alt=""></p><blockquote><p>关键技术点：</p><ol><li><p>用UserService的方法hasPermission来判断是否有权限</p></li><li><p>如果没有权限用$this-&gt;gotoLoginPage来跳转页面</p></li><li><p>用$this-&gt;initVar()初始化默认变量值</p></li></ol></blockquote><p>这是标准的ThinkPHP 3.2的Controller开发内容，请参考<a href="https://www.kancloud.cn/manual/thinkphp/1712" target="_blank" rel="noopener noreferrer"><code>ThinkPHP 3.2开发文档</code><span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a>。</p><p>5、编写业务模块View</p><p>业务模块的入口页面通常的action就用index()，对应的View就是index.html</p><p>这是标准的ThinkPHP 3.2的View开发内容，请参考<a href="https://www.kancloud.cn/manual/thinkphp/1785" target="_blank" rel="noopener noreferrer"><code>ThinkPHP 3.2开发文档</code><span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a>。</p><p>6、修改MainMenuController的代码</p><p>MainMenuController 位于 <a href="https://gitee.com/crm8000/PSI/blob/master/web/Application/Home/Controller/MainMenuController.class.php" target="_blank" rel="noopener noreferrer"><code>/web/Application/Home/Controller/MainMenuController.class.php</code><span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a></p><p>在MainMenuController的方法 <code>navigateTo</code> 中增加相应的跳转代码。</p><!--]--></div><footer class="page-meta"><!----><!----><!----></footer><!----><!--[--><!--]--></main><!--]--></div><!----><!--]--></div>
    <script type="module" src="/help/assets/app.ae8b26c7.js" defer></script>
  </body>
</html>
